<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="common/include :: header"></head>
<body class="gray-bg">
<!-- 配置grid -->
<div class="container" style="padding:  0px 10px !important;margin-top: -10px;text-align: center !important;">
    <div class="row">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>权限配置</h5>
            </div>
            <div class="ibox-content">
                <ul id="zTree" class="ztree"></ul>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <button class="btn btn-sm btn-info" type="button" id="btn_save">
                <i class="ace-icon fa fa-check bigger-110"></i>保存
            </button>
            &nbsp;
            <button class="btn btn-sm btn-danger" type="button" id="btn_close">
                <i class="ace-icon fa fa-close bigger-110"></i>关闭
            </button>
        </div>
    </div>
</div>

<div th:include="common/include :: footer"></div>

<script type="text/javascript" th:inline="javascript">
    $(function () {
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引

        $("#btn_close").bind("click", function () {
            parent.layer.close(index);
        });

        $("#btn_save").bind("click", function () {
            var ids = zTreeCheckedNodes("zTree");
            $.ajax({
                cache : true,
                type : "POST",
                url : ctxPath + "role/setAuthority",
                data : {"ids": ids,"roleId": [[${roleId}]]}, // 你的formid
                async : false,
                error : function(request) {
                    alert("Connection error");
                },
                success : function(data) {
                    if (data.code == 200) {
                        parent.layer.msg("操作成功");
                        parent.reLoad();
                        parent.layer.close(index);
                    } else {
                        parent.layer.msg(data.message);
                    }
                }
            });
        });

        initZtree();
    });

    function initZtree() {
        var ztree = new $ZTreePlus("zTree", ctxPath + "module/menuTreeListByRoleId/" + [[${roleId}]]);
        ztree.init(2);
    }

    function zTreeCheckedNodes(zTreeId) {
        var zTree = $.fn.zTree.getZTreeObj(zTreeId);
        var nodes = zTree.getCheckedNodes();
        var ids = "";
        for (var i = 0, l = nodes.length; i < l; i++) {
            ids += "," + nodes[i].id;
        }
        return ids.substring(1);
    }
</script>

</body>
</html>